package net.heri.xmppchat.ui;

import net.heri.xmppchat.R;
import net.heri.xmppchat.controllers.ChatController;
import net.heri.xmppchat.controllers.ChatControllerEvents;
import roboguice.activity.RoboActivity;
import roboguice.inject.ContentView;
import roboguice.inject.InjectView;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;

import com.google.inject.Inject;

@ContentView(R.layout.chatroom_activity)
public class ChatRoomActivity extends RoboActivity implements OnClickListener {

	private final String TAG = ChatRoomActivity.class.getSimpleName();
	
	@InjectView(R.id.tv_label) TextView label;
	@InjectView(R.id.bt_settings) Button settingButton;
	@InjectView(R.id.bt_update) Button updateButton;	

	@Inject private ChatController mController;
	
	private Handler mHandler = new Handler(){
		public void handleMessage(Message msg) {
			label.setText((String)msg.obj);
		};
	};
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {		
		super.onCreate(savedInstanceState);
		
		mController.setHandler(mHandler);
		
		settingButton.setOnClickListener(this);		
		updateButton.setOnClickListener(this);	
		
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.bt_settings:
			Log.i(TAG, "start settingActivity");
			
			Intent intent = new Intent(ChatRoomActivity.this, ChatSettingsActivity.class);
			startActivity(intent);
			break;
		case R.id.bt_update:
			Log.i(TAG, "start settingActivity");
			
			eventManager.fire(new ChatControllerEvents.OnLabelChanged());
			break;
		
		}
	}	
	
}
